feat(normalize): render post attachment zone in convertPost - #18
Merged
mazhe-nerd merged 4 commits intoAug 31, 2026
Merged
Conversation
The rich-text attachment zone (top-level files array) was ignored by the post converter: only the locale document (title/content) was flattened and scanned for resources, so attachments attached to a rich-text message were invisible to channel consumers. - render attachment-zone files as <file key=... name=.../> lines and is_folder entries as <folder .../> lines, matching the standalone file/folder converters - surface attachment-zone files as ResourceDescriptor(type=file) so they are downloadable; folders remain tag-only like the folder converter - cover with tests: rendering + resource extraction, empty files array
yjhcjykwbk-jlsec
force-pushed
the
feat/post-attachment-zone
branch
from
August 31, 2026 09:30
e4d7480 to
aa84321
Compare
…lues Follow-up fixes on top of the attachment-zone support, covering paths the original change left untested: - Read the attachment zone before the locale guard. `files` is a sibling of the locale documents, not part of one, so a post whose locale document cannot be unwrapped was silently dropping its attachments entirely. - Normalize entries in `topLevelAttachments` instead of casting the raw wire record. A non-string `file_name` reached `escapeAttr` and threw, which `dispatchConvert` traps by falling back to the unknown-message converter — replacing the entire message, body and all, with a placeholder. - Compare `is_folder` against `true` rather than testing truthiness, so a string `"false"` cannot hide a real, downloadable file behind a `<folder/>` tag and drop it from `resources`. - Escape the key as well as the name when rendering tags, matching how these tags are produced elsewhere. The narrowed `PostAttachment` type now states what the extractor actually guarantees, which removes the redundant empty-key check and the duplicated attribute construction in the render loop. Adds regression tests for each path, plus an ordering assertion the existing `toContain` checks could not make.
…nvariant Addresses review follow-ups on the attachment-zone change: - The rich-text placeholder string was repeated at three exits; name it once so the three agree by construction. - Add a test for the invariant the attachment zone relies on but nothing covered: attachments are appended to the body's own resources rather than replacing them, so an image and a media element still survive alongside an attachment-zone file. - Drop a duplicated restatement of the file-vs-folder rule; it is already documented where the rule is enforced.
Mechanical only: biome wraps the long toContainEqual argument. No assertion or behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The rich-text attachment zone (top-level
filesarray on a post message) was ignored byconvertPost: only the locale document (title/content/content_v2) was flattened and scanned for resources, so attachments attached to a rich-text message were invisible to channel consumers (agents/CLIs).This PR makes the attachment zone visible and downloadable:
src/normalize/converters/post.tstopLevelAttachments(): extract the top-levelfiles: [{file_key, file_name, is_folder}]array<file key="..." name="..."/>/<folder key="..." name="..."/>lines after the body, matching the standalone file/folder convertersResourceDescriptor(type: 'file')so they are downloadable; folders stay tag-only (mirrors the standalone folder converter'sresources: [])src/normalize/__tests__/converters.test.ts: two new tests — rendering + resource extraction, and emptyfilesarray toleranceWire shape
{ "zh_cn": { "title": "报告", "content": [...] }, "files": [ { "file_key": "file_a", "file_name": "report.pdf" }, { "file_key": "dir_1", "file_name": "assets", "is_folder": true } ] }renders as:
with
resources: [{type: 'file', fileKey: 'file_a', fileName: 'report.pdf'}].Test